<template>
  <div id="profile">
    <profile-nav-bar />
    <profile-base-info :base-info="baseInfo" />
    <profile-number-info :digit-info="digitInfo" />
    <profile-service-info />
    <router-view />
  </div>
</template>

<script>
import ProfileNavBar from "./childComps/ProfileNavBar";
import ProfileBaseInfo from "./childComps/ProfileBaseInfo";
import ProfileNumberInfo from "./childComps/ProfileNumberInfo";
import ProfileServiceInfo from './childComps/ProfileServiceInfo'

import { getUser } from "network/profile";

import { SET_USER_INFO } from "store/mutations.type";
export default {
  name: 'Profile',
  data() {
    return {
      baseInfo: {},
      digitInfo: [],
    };
  },
  created() {
   
    this.getUser(localStorage.getItem("user_id"));
    // 防止出现登录成功数据没有得到的bug
    this.$bus.$on("getLogin", () => {
      this.getUser(localStorage.getItem("user_id"));
    });
  },

  methods: {
    getUser(user_id) {
      getUser(user_id).then((res) => {
        this.digitInfo.push(res.point);
        this.digitInfo.push(res.gift_amount);
        this.digitInfo.push(res.balance);

        this.baseInfo = res;
        this.$store.commit(SET_USER_INFO, this.baseInfo);
      });
    },
  },
  components: {
    ProfileNavBar,
    ProfileBaseInfo,
    ProfileNumberInfo,
    ProfileServiceInfo
  },
};
</script>
<style lang="less" scoped>
#profile {
  height: 100vh;
  background-color: #f5f5f5;
}
</style>